

var QrH5MubanItemModel = $.extend(TradeModel, {
    selRow: null,
    editor:{
        title: "属性",
        winid:'QrH5MubanItem_EditForm',
        formid:'QrH5MubanItem_EditForm_fm',
        width:720,
        height:300
    },
    postAction: 'add',
    url: '/qrmgr/qrh5mubanitem',
    title: "标题",
    idField: "itemId",
    titleField: "attrName",
    toolbar: 'QrH5MubanItem_Toolbar',
    datagrid: 'QrH5MubanItem_Grid'
});

QrH5MubanItemModel.reload =function() {
    $('#QrH5MubanItem_EditForm').dialog('close');
    ReloadQrH5MubanItemList();
}


function fun_FindRowById(id) {
    var cRows = $('#QrH5MubanItem_Grid').datagrid('getRows');
    if (id == undefined || id == '' || id == null) return null;
    for (i = 0; i < cRows.length; i++) {
        if (cRows[i][QrH5MubanItemModel.idField] == id) {
            return cRows[i];
        }
    }
    return null;
}




function ShowQrH5MubanItemEditForm(id) {
    QrH5MubanItemModel.selRow = fun_FindRowById(id);
    if (QrH5MubanItemModel.selRow == null) {
        QrH5MubanItemModel.selRow={};
        QrH5MubanItemModel.postAction = 'add';
        QrH5MubanItemModel.selRow['attrType']='INPUT';
        QrH5MubanItemModel.selRow['required']='false';
    }
    else {
        QrH5MubanItemModel.postAction = 'update';
    }

    $('#QrH5MubanItem_EditForm_fm').form('clear' );
    QrH5MubanItemModel.selRow['mubanId']=$('#rootmubanId').val();

    $('#QrH5MubanItem_EditForm_fm').form('load', QrH5MubanItemModel.selRow);
    $('#QrH5MubanItem_EditForm').dialog({
        top: "10px",
        width:350,
        height:280,
        resizable: false,
        maximizable: false
    })
        .dialog('open')
        .dialog('setTitle', (QrH5MubanItemModel.postAction == 'add') ? '新增'  : '修改' + QrH5MubanItemModel.selRow[QrH5MubanItemModel.titleField]);
}
function SaveQrH5MubanItem() {
    QrH5MubanItemModel.submit();

}
function DelQrH5MubanItem( id,title) {
    QrH5MubanItemModel.del(id,title);
}

function QrH5MubanItemSearchbox(value, name) {
    if (value == "" || value == null) {
        $.messager.alert('提示', '请输入关键字!', 'info');
    }
    else {
        $('#QrH5MubanItem_Grid').datagrid('reload');
    }

}

function ReloadQrH5MubanItemList() {
    $('#QrH5MubanItem_Grid').datagrid('reload');
}



$(function () {
    $('#QrH5MubanItem_Grid').datagrid({
        pageSize: 20,
        fit: true,
        singleSelect: true,
        fitColumns: true,
        pagination: true,
        method: 'post',
        idField: QrH5MubanItemModel.idField,
        treeField: QrH5MubanItemModel.titleField,
        url: Onluy.basePath()+QrH5MubanItemModel.url+'/list',
        loader:QrH5MubanItemModel.Loader,
        toolbar: '#QrH5MubanItem_Toolbar',
        columns: [
            [
                { field: 'attrType', title: '类型', width:50, align: 'left',sortable:true },
                { field: 'attrCode', title: '编码', width:100, align: 'left',sortable:true },
                { field: 'attrName', title: '名称', width:150, align: 'left',sortable:true },
                { field: 'attrValue', title: '属性值', width:350, align: 'left',sortable:true },
                { field: 'required', title: '必填', width:50, align: 'left',sortable:true },
                {
                    field: 'opt', title: '操作', width: 100, align: 'center',
                    formatter: function (value, rec) {
                        return '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/pencil.gif" onclick="ShowQrH5MubanItemEditForm(\'' + rec[QrH5MubanItemModel.idField] + '\');"   />'
                            + '<img class="btn-16" src="'+Onluy.basePath()+'/Images/icos/16/delete.gif" onclick="DelQrH5MubanItem(\'' + rec[QrH5MubanItemModel.idField] + '\',\'' + rec[QrH5MubanItemModel.titleField] + '\');"  />';
                    }
                }
            ]
        ],


        onLoadError: function (res) {
            QrH5MubanItemModel.ShowException(res);
        },
        onLoadSuccess: function (data) {
            if(data.success){ }
            else if(data.msg){
                $.messager.alert('加载错误', data.msg );
            }
        },
        onDblClickRow: function (rowIndex, rowData) {
            ShowQrH5MubanItemEditForm(rowData[QrH5MubanItemModel.idField]);
        },
        onBeforeLoad: function (param) {
            param['mubanId']=$('#rootmubanId').val();
            param['catchKey'] = Math.random();
            param['name'] = $('#QrH5MubanItem_ss').searchbox('getName');
            param['value'] = $('#QrH5MubanItem_ss').searchbox('getValue');
        }
    });
    //设置分页控件
    var p = $('#QrH5MubanItem_Grid').datagrid('getPager');
    $(p).pagination({
        pageSize: 20, //每页显示的记录条数，默认为10
        pageList: [20, 30, 50, 100], //可以设置每页记录条数的列表
        beforePageText: '第', //页数文本框前显示的汉字
        afterPageText: '页    共 {pages} 页',
        displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
        onBeforeRefresh: function () {
            $(this).pagination('loading');
            $(this).pagination('loaded');
        }
    });

});



